<title>用户管理</title>
  
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>用户管理</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-userfront-formlist">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">标题</label>
          <div class="layui-input-block">
            <input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">来源</label>
          <div class="layui-input-block">
            <input type="text" name="email" placeholder="请输入" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
          </button>
        </div>
      </div>
    </div>
    
    <div class="layui-card-body">
      <div style="padding-bottom: 10px;">
        <button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel">删除</button>
        <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>
      </div>
      
      <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
      <script type="text/html" id="table-useradmin-webuser">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
      </script>
    </div>
  </div>
</div>

<script>
    layui.use('dataList', layui.factory('dataList')).use(['admin', 'dataList', 'table'], function(){
        var $ = layui.$
        ,admin = layui.admin
        ,view = layui.view
        ,table = layui.table
        ,form = layui.form;

        //事件
        var active = {
            batchdel: function(){
            var checkStatus = table.checkStatus('LAY-user-manage')
            ,checkData = checkStatus.data; //得到选中的数据

            if(checkData.length === 0){
                return layer.msg('请选择数据');
            }
            
            layer.prompt({
                formType: 1
                ,title: '敏感操作，请验证口令'
            }, function(value, index){
                layer.close(index);
                
                layer.confirm('确定删除吗？', function(index) {
                    table.reload('LAY-user-manage');
                    layer.msg('已删除');
                });
            });
            }
            ,add: function(){
            admin.popup({
                title: '添加内容'
                ,area: ['80%', '80%']
                ,id: 'LAY-popup-user-add'
                ,success: function(layero, index){
                view(this.id).render('neirong/add').done(function(){
                    form.render(null, 'layuiadmin-form-useradmin');
                    
                    //监听提交
                    form.on('submit(data-add)', function(data){
                        console.log(123456);
                        var field = data.field; //获取提交的字段
                        
                        layer.msg('提交成功', {icon: 1,time: 3000}, function(){
                            layui.table.reload('LAY-user-manage'); //重载表格
                            layer.close(index); //执行关闭 
                        });
                    });
                });
                }
            });
            }
        };

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>